package com.econ.powercloud.ems.service.biz;

import com.econ.powercloud.ems.common.enums.EnumMethod;
import com.econ.powercloud.ems.pojo.ApiDataVO;
import com.google.common.collect.Lists;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * @author zjr
 * @create 2021/7/12 上午9:34
 * @description 字典service
 */
@Service
public class DictionaryApiBizService {

    /**
     * 对统一的枚举生成对应的字典，要求使用的枚举需要继承EnumMethod
     * @param type
     * @param filterList: 不需要展示给前端的数据
     * @return
     */
    public List<ApiDataVO> getApiDataVOList(EnumMethod[] type, List<EnumMethod> filterList){
        List<ApiDataVO> resultVOS = Lists.newArrayList();
        Arrays.asList(type).forEach(apiType -> {
            if(CollectionUtils.isEmpty(filterList) || !filterList.contains(apiType)){
                resultVOS.add(ApiDataVO.builder().code(apiType.getCode()).name(apiType.getDesc()).build());
            }
        });
        return resultVOS;
    }
}
